package com.six.firstpage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.core.entity.HeadNav;
import com.six.core.vo.Result;
import com.six.firstpage.service.HeadNavService;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.service.ApiListing;

import java.util.List;

/**
 * @author:zzh
 * @create: 2023-02-27 10:47
 * @Description:
 */
@Api(value = "firstpage/headnav", tags = {"导航栏后台接口"})
@RestController
@RequestMapping("firstpage/headnav")
public class HeadNavController {

    @Autowired
    private HeadNavService headNavService;

    @GetMapping("getAllHeadNav")
    public Result getAllHeadNav(){
        List<HeadNav> allHeadNav = headNavService.getAllHeadNav();
        return new Result(2000,"查询所有导航成功",allHeadNav);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "title", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "current", value = "", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = false)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("getHeadNavByTitle/{current}/{pageSize}")
    public Page<HeadNav> getHeadNavByTitle(String title,Integer status, @PathVariable @RequestParam(defaultValue = "1") Integer current, @PathVariable @RequestParam(defaultValue = "5") Integer pageSize){
        return headNavService.getHeadNavByTitle(title,status,current,pageSize);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "HeadNav", name = "headNav", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("addHeadNav")
    public String addHeadnav(@RequestBody HeadNav headNav){
        Integer i = headNavService.addHeadNav(headNav);
        if (i>0){
            return "添加导航栏成功";
        }
        return "添加导航栏失败";
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "HeadNav", name = "headNav", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "PUT")
    @PutMapping("updateHeadNav")
    public String updateHeadNav(@RequestBody HeadNav headNav){
        Integer i = headNavService.updateHeadNav(headNav);
        if (i>0){
            return "修改导航栏成功";
        }
        return "修改导航栏失败";
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "headId", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "GET")
    @GetMapping("delHeadNav/{headId}")
    public String delHeadNav(@PathVariable Integer headId){
        Integer i = headNavService.delHeadNav(headId);
        if (i>0){
            return "删除导航栏成功";
        }
        return "删除导航栏失败";
    }


}
